<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id ID
 * @property int $userid 用户ID
 * @property int $anchor_userid 主播用户ID
 * @property int $room_id 房间ID
 * @property string $room_name 房间名称
 * @property int $add_time 关注时间
 * @property-read null|User $user 
 * @property-read null|UserModelAnchor $anchor 
 * @property-read null|Live $live 
 */
class FollowAnchor extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'follow_anchor';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'userid', 'anchor_userid', 'room_id', 'room_name', 'add_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'userid' => 'integer', 'anchor_userid' => 'integer', 'room_id' => 'integer', 'add_time' => 'integer'];

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'anchor_userid')->select(['id', 'username', 'avatar', 'nickname']);
    }

    public function anchor()
    {
        return $this->hasOne(UserModelAnchor::class, 'userid', 'anchor_userid');
    }

    public function live()
    {
        return $this->hasOne(Live::class, 'userid', 'anchor_userid');
    }
}
